package com.squirrel.facade;

import com.squirrel.service.CreateSelectSql;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 对外提供sql查询的方法
 *
 * @author wangyan
 */
public class Select implements SqlOperate {

    private CreateSelectSql createSQL;

    public Select() {
        this.createSQL = new CreateSelectSql();
    }

    public CreateSelectSql getCreateSQL() {
        return this.createSQL;
    }

    public final Select distinct() {
        createSQL.setDistinct();
        return this;
    }

    public final Select fields(String... fields) {
        createSQL.setQueryFields(fields);
        return this;
    }

    public final Select count() {
        createSQL.setCount();
        return this;
    }

    public final Select from(String tableName) {
        createSQL.setQueryTable(tableName);
        return this;
    }

    public Select where(String field, String condition, Long value) {
        createSQL.setWhere(field, condition, value);
        return this;
    }

    public Select where(String field, String condition, String value) {
        createSQL.setWhere(field, condition, value);
        return this;
    }

    public Select where(String field, String condition, LocalDateTime value) {
        createSQL.setWhere(field, condition, value);
        return this;
    }

    public Select where(String field, String condition, List<Object> valueList) {
        createSQL.setWhere(field, condition, valueList);
        return this;
    }

    public Select where(String field, String condition, Object valueList) {
        createSQL.setWhere(field, condition, valueList);
        return this;
    }

    public final Select and(String field, String condition, String value) {
        createSQL.setAnd(field, condition, value);
        return this;
    }

    public void foreach(String field, String condition, String value) {
        createSQL.setForeach(field, condition, value);
    }

    public final Select and(String field, String condition, long value) {
        createSQL.setAnd(field, condition, value);
        return this;
    }

    public final Select and(String field, String condition, LocalDate value) {
        createSQL.setAnd(field, condition, value);
        return this;
    }

    public final Select and(String field, String condition, LocalDateTime value) {
        createSQL.setAnd(field, condition, value);
        return this;
    }

    public final Select and(String field, String condition, List<Object> valueList) {
        createSQL.setAnd(field, condition, valueList);
        return this;
    }

    public final Select and(String field, String condition, Object valueList) {
        createSQL.setAnd(field, condition, valueList);
        return this;
    }

    public final Select or(String field, String condition, String value) {
        createSQL.setOr(field, condition, value);
        return this;
    }

    public final Select or(String field, String condition, LocalDate value) {
        createSQL.setOr(field, condition, value);
        return this;
    }

    public final Select join(String joinType, String joinTableName) {
        createSQL.setJoin(joinType, joinTableName);
        return this;
    }


    public final Select on(String a, String b) {
        createSQL.setOn(a, b);
        return this;
    }
    /**
     *
     * @param a 字段
     * @param b asc 升序 desc 降序
     * @return
     */
    public final Select orderBy(String a, String b) {
        createSQL.setOrderbyField(a);
        createSQL.setOrderbyColline(b);
        return this;
    }
}
